Repository navigation
Conversation
QuantityTensor arithmetic, powers, reductions and selections now return QuantityTensor at the type level, and mixing a scalar Quantity with a tensor gives a QuantityTensor. Arithmetic on the Quantity | QuantityTensor union now type-checks. Runtime behaviour is unchanged.
The concrete classes become private (_Quantity, _Tensor, _QuantityTensor). Values are created with number * unit and tensor(...), which return the public types; Quantity(value, unit) construction is removed, including in transform bodies. QuantityTensor satisfies Quantity but not the unitless Tensor. Number is float | Tensor.
brocksam
marked this pull request as draft
November 18, 2026 19:11
Annotated[Quantity, DIM] now accepts a scalar or a tensor; Quantity | QuantityTensor normalises to it and scalar-only ports are removed. A dimensionality Bilt cannot read (in a union, a generic, or a subscripted generic type alias) now raises instead of being silently dropped. Tests and benchmarks use Quantity and Number in place of the old unions, with one alias per dimension.
The quantity annotations reference opens with the 2x2 grid (Quantity, QuantityTensor, Number, Tensor) and one alias per dimension; the units and tensors guides, API pages and worked examples drop the Pointwise alias pairs, the old unions and Quantity(value, unit). Tensors print with their public names.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Quantity and tensor annotations as protocols
A port annotation answers two independent questions: does the value carry a unit, and must it be a tensor? Until now the answer was spelt by choosing among four concrete classes and unions of them. So the same intent was written differently on a system field (
Quantity | QuantityTensor) and in an equation (Quantity), every dimension needed an alias pair (PointwiseMass/Mass), and arithmetic on the union failed to type-check.The four public names are now protocols that state each answer directly:
QuantityQuantityTensorNumberTensorOne alias per dimension now serves systems, equations and transforms:
Changes
QuantityTensorkeep the unit for type checkers. Mixing a scalar quantity and a tensor gives aQuantityTensor.Quantity,QuantityTensorandTensorare runtime-checkable protocols.Numberisfloat | Tensor.QuantityTensoris aQuantity. It is not a unitlessTensororNumber, so type checkers now reject a unit-bearing tensor at a unitless port._Quantity,_Tensor,_QuantityTensor).2.0 * kilogramandtensor(...)return the publi the public names.Annotated[Quantity, DIM]accepts a scalar or a te | QuantityTensor` normalises to it. Scalar-only portsare removed.BiltPortDe being silently dropped. This covers dimensions inside aunion (Annotated[...] | None), inside a generic, or in a subscripted generic alias (Length[Quantity]`).Breaking changes
Quantity(value, unit)no longer constructs a quantity. Writevalue * unit(aninttimes a unit now works too).Tensor(...)and
Tensor.scalar(...)are replaced bytensor(...).degrees * absolute_celsiusreplacesQuantity(degrees, absolute_celsius).Annotated[Quantity, DIM]on a system field acceptcalar-only quantity annotation..valueon aQuantityis aNumber. A transform that returnsx.convert_to(unit).valueis annotated-> Number.BiltPortDeclarationError.Existing
Quantity | QuantityTensorand `float | Tensog.Testing
is required, or a unit-bearing tensor passed as aNumber`;benchmarks/test_nested_coupled_plan_search.py::test_nested_coupled_plan_search[coupled]. That test fails identically onmain(1b1b1fa), so it pre